package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.MyWalletContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.MyWalletPresenter;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/22 16:17
 * 功能描述： 我的钱包
 * 联系方式：1037438704@qq.com
 */
public class MyWalletActivity extends BaseActivity implements MyWalletContract {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.image_question)
    ImageView imageQuestion;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.ll_my_binding)
    LinearLayout llMyBindig;
    @BindView(R.id.ll_detailed)
    LinearLayout ll_detailed;
    @BindView(R.id.text_preservation)
    TextView textPreservation;
    @BindView(R.id.text_balance)
    TextView textBalance;
    @BindView(R.id.text_bind)
    TextView textBind;
    private MyWalletPresenter myWalletPresenter;
    private String is_bind;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_my_wallet;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        imageQuestion.setVisibility(View.VISIBLE);
        textCenter.setText("我的钱包");
        imageleftFinish.setVisibility(View.VISIBLE);
        myWalletPresenter = new MyWalletPresenter(this, this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        myWalletPresenter.getMyWallet(token);
    }

    @OnClick({R.id.image_left_finish, R.id.image_question, R.id.ll_my_binding, R.id.ll_detailed, R.id.text_preservation})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.image_question:
                startActivity(new Intent(this, CommonProblemActivity.class));
                break;
            case R.id.ll_my_binding:
//                if (is_bind.equals("1")) {
//                    return;
//                }
                //支付宝绑定
                startActivity(new Intent(this, BindingAliPayActivity.class));
                break;
            case R.id.ll_detailed:
                //账户明细
                startActivity(new Intent(this, AccountDetailsActivity.class));
                break;
            case R.id.text_preservation:
                //立即提现
                if (is_bind.equals("2")) {
                    ToastUtil.show("请先绑定支付宝！");
                    return;
                }
                Intent intent = new Intent(this, PreservationActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("zhifubao", textBind.getText().toString().trim());
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            default:
        }
    }

    @Override
    public void Success(Map<String, String> map) {
        textBalance.setText(map.get("balance"));
//        是否绑定支付宝 1是 2否
        is_bind = map.get("is_bind");
        if (is_bind.equals("1")) {
            textBind.setText(map.get("alipay_account"));
        } else {
            textBind.setText("请绑定支付宝");
        }
    }

    @Override
    public void showLoading() {
        WaitDialog.show(me, "数据请求中");
    }
}
